/*
 * @Description: 
 * @Author: 马爽
 * @Date: 2021-03-09 00:32:31
 * @LastEditTime: 2021-03-10 11:31:49
 * @LastEditors: 马爽
 */

import React, { FC } from 'react'
import { useDispatch } from 'umi';
import { Button, Select, Form} from 'antd';
import { IdentityListType, View_authority } from '@/interface/user';

const { Option } = Select;

const layout = {
  labelCol: { span: 8 },
  wrapperCol: { span: 16 },
};

const tailLayout = {
  wrapperCol: { offset: 1, span: 16 },
};

interface Iprops {
    identityList: IdentityListType[],
    viewAuthorityList: View_authority[]
}

const SetIdentityView:FC<Iprops> = ({identityList,viewAuthorityList}) => {
    const dispatch = useDispatch();
    
    const [form] = Form.useForm();

    const onReset = () => {
        form.resetFields();
    };

    function handleChange(value: any) {
        console.log(`selected ${value}`);
    }
        
    const onFinish = (values: any) => {
        console.log('Success:', values);
        //是否成功 
        dispatch({
            type:'userManage/setIdentityView',
            payload:{...values}
        })
    };
    
    return (
        <div className='addbox'>
          <div className='btn'>
            <Button>给身份设置视图权限</Button>
          </div>
          <Form
            form={form}
            {...layout}
            name="basic"
            onFinish={onFinish}
          >

            <Form.Item
                name="identity_id"
                rules={[{ required: true, message: '身份id' }]}
            >
              <Select style={{ width: 124 }} onChange={handleChange} placeholder={'请选择身份id'}>
                {
                  identityList.map((item,index) => {
                    return (
                      <Option value={item.identity_id} key={index}>{item.identity_text}</Option>
                    )
                  })
                }
              </Select>
            </Form.Item>
            
            <Form.Item
                name="view_authority_id"
                rules={[{ required: true, message: '择视图权限' }]}
            >
                <Select  style={{ width: 124 }} onChange={handleChange} placeholder={'请选择视图权限'}>
                {
                    viewAuthorityList.map((item,index) => {
                    return (
                        <Option value={item.view_authority_id} key={index}>{item.view_authority_text}</Option>
                    )
                    })
                }
                </Select>
            </Form.Item>

            <Form.Item {...tailLayout}>
              <Button type="primary" htmlType="submit">
                确定
              </Button>
              <Button htmlType="button" onClick={onReset}>
                重置
              </Button>
            </Form.Item>
          </Form>
        </div>
    )
}

export default SetIdentityView;